﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;

namespace Medianamik.UI.Controls
{
    [ToolboxData("<{0}:BetterImageButton runat=server></{0}:BetterImageButton>")]
    public class BetterImageButton : System.Web.UI.WebControls.ImageButton
    {
        public virtual string DisabledImageUrl
        {
            get
            {
                if (ViewState["DisabledImageUrl"] == null)
                    return default(String);

                return ViewState["DisabledImageUrl"].ToString();
            }
            set
            {
                ViewState["DisabledImageUrl"] = value;
            }
        }

        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            if (Enabled || String.IsNullOrEmpty(DisabledImageUrl))
            {
                base.Render(writer);
            }
            else
            {
                writer.Write("<img id=\"{3}\" src=\"{0}\" alt=\"{1}\" class=\"{2}\" />",
                    DisabledImageUrl, Text, CssClass, ClientID);
            }
        }
    }
}
